package com.maikang.exammall.entity.dto;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.maikang.exammall.entity.constant.BizCode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;


@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Data
public class ResponseDTO<T> implements Serializable {

    private Integer ecode;
    private String emsg;
    private T data;
    private static final long serialVersionUID = 1L;

    public ResponseDTO(Integer code, String msg) {
        this.ecode = code;
        this.emsg = msg;
    }


    public static ResponseDTO failed() {
        return new ResponseDTO(BizCode.InternalServerException, "系统繁忙,请稍后再试");
    }

    public static ResponseDTO failed(String msg) {
        return new ResponseDTO(BizCode.InternalServerException, msg);
    }


    public static ResponseDTO badRequest(String msg) {
        return new ResponseDTO(BizCode.BadRequest, msg);
    }

    public static ResponseDTO ok() {
        return new ResponseDTO(BizCode.Ok, "成功");
    }


    public static<K> ResponseDTO<K> ok(K data) {
        return new ResponseDTO<K>(BizCode.Ok, "成功", data);
    }

}
